package com.fjzx.androidframe.base.annotation.injector;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fjzx.androidframe.base.activity.BaseSimpleActivity;
import com.fjzx.androidframe.base.annotation.ContentView;
import com.fjzx.androidframe.base.fragment.BaseSimpleFragment;

/**
 * {@link ContentView} 注解注入器
 *
 * @author xiongyongcong
 */
public class ContentViewInjector {
    /**
     * 注入到{@link BaseSimpleActivity}
     *
     * @param activity
     */
    public static int inject(BaseSimpleActivity activity) {
        Class<?> clazz = activity.getClass();
        if (clazz.isAnnotationPresent(ContentView.class)) {
            ContentView contentView = clazz.getAnnotation(ContentView.class);
            return contentView.value();
        }
        return 0;
    }

    /**
     * 注入到{@link BaseSimpleFragment}
     *
     * @param fragment
     * @param inflater
     * @param container
     * @return
     */
    public static View inject(BaseSimpleFragment fragment, LayoutInflater inflater, ViewGroup container) {
        Class<?> clazz = fragment.getClass();
        if (clazz.isAnnotationPresent(ContentView.class)) {
            ContentView contentView = clazz.getAnnotation(ContentView.class);
            int contentViewId = contentView.value();
            return inflater.inflate(contentViewId, container, false);
        }
        return null;
    }
}
